﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Iworld.Toolkit.Helper
{
    /// <summary>
    /// Xaml相关的帮助类
    /// </summary>
    public static class XamlHelper
    {
        /// <summary>
        /// 获取元素的上下文对象
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="element"></param>
        /// <returns></returns>
        public static T GetDataContext<T>(object element)
        {
            FrameworkElement fe = (element as FrameworkElement);
            if (fe == null) throw new Exception("对象必须为FrameworkElement类型");
            return (T)(fe.DataContext);
        }
    }
}
